<%--
  Created by IntelliJ IDEA.
  User: LL
  Date: 2024/8/16
  Time: 18:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>首页</title>
    <script type="text/javascript" src="js/jquery-1.8.3%20(1).js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.get("book/queryAll", function (books) {
                JSON.stringify(books);
                $("tbody").empty();
                for (var i = 0; i < books.length; i++) {
                    $("<tr>" +
                        "<td>" + books[i].BOOKNAME + "</td>" +
                        "<td>" + books[i].BOOKAUTHOR + "</td>" +
                        "<td>" + books[i].BOOKPUBLISH + "</td>" +
                        "<td>" + books[i].BOOKPAGE + "</td>" +
                        "<td>" + books[i].BOOKPRICE + "</td>" +
                            "<td><input type='button' id='"+books[i].BOOKID+"' name='button1' value='删除'></td>" +
                            "</tr>").appendTo("tbody");

                };

            });
            $("[type='button']").click(function(){

                var val = $("select").val();
                var str = $("[name='qval']").val();

                $.get("book/querybook", {"query": val, "str": str}, function (books) {
                   JSON.stringify(books);
                    $("tbody").empty();
                    for (var i = 0; i < books.length; i++) {
                        $("<tr>" +
                            "<td>" + books[i].BOOKNAME + "</td>" +
                            "<td>" + books[i].BOOKAUTHOR + "</td>" +
                            "<td>" + books[i].BOOKPUBLISH + "</td>" +
                            "<td>" + books[i].BOOKPAGE + "</td>" +
                            "<td>" + books[i].BOOKPRICE + "</td>" +
                                "<td><a name='"+books[i].BOOKID+"' title='删除'>删除</a></td>" +
                                "</tr>").appendTo("tbody");
                    }

                });
            })

        })
        //删除
       $(document).on("click","[title='删除']",function () {
           var id = $(this).attr("name");
               alert(id)
           $.get("book/delectById",{"bid":id},function (obj) {
               JSON.stringify(obj);
               alert(obj.mess);
               $("tbody").empty();
               var books =obj.books;
               for (var i = 0; i < books.length; i++) {
                   $("<tr>" +
                       "<td>" + books[i].BOOKNAME + "</td>" +
                       "<td>" + books[i].BOOKAUTHOR + "</td>" +
                       "<td>" + books[i].BOOKPUBLISH + "</td>" +
                       "<td>" + books[i].BOOKPAGE + "</td>" +
                       "<td>" + books[i].BOOKPRICE + "</td>" +
                       "<td><input type='button' name='"+books[i].BOOKID+"' title='删除'></td>" +
                       "</tr>").appendTo("tbody");
               }
           })
       })


    </script>
</head>
<body>
<a href="add.jsp">增加图书</a>
<table border="1">
    <thead style="color: #04010e">
    <tr style="color: red">
        <td>书名</td>
        <td>作者</td>
        <td>出版社</td>
        <td>页数</td>
        <td>价格</td>
        <td>操作</td>

    </tr>
    </thead>
    <tbody>

    </tbody>
</table>
<select name="query">
    <option value="-1">----请选择</option>
    <option value="1">书名</option>
    <option value="2">作者名</option>
    <option value="3">出版社</option>
</select>
<input type="text" name="qval">
<input type="button" value="查询">

</body>
</html>
